package me.kennylee.mobile.sms.code;

/**
 * <p> 错误码 </p>
 * <p>Created on 24/3/2018.</p>
 *
 * @author kennylee
 */
public enum AlidayuSmsCode {
    OK("OK", "请求成功"), MOBILE_NUMBER_ILLEGAL("isv.MOBILE_NUMBER_ILLEGAL", "非法手机号"),
    BUSINESS_LIMIT_CONTROL("isv.BUSINESS_LIMIT_CONTROL", "业务限流"),
    MOBILE_COUNT_OVER_LIMIT("isv.MOBILE_COUNT_OVER_LIMIT", "手机号码数量超过限制"),
    BLACK_KEY_CONTROL_LIMIT("isv.BLACK_KEY_CONTROL_LIMIT", "黑名单管控"),
    PARAM_LENGTH_LIMIT("isv.PARAM_LENGTH_LIMIT", "参数超出长度限制"),
    INVALID_PARAMETERS("isv.INVALID_PARAMETERS", "参数异常"),
    AMOUNT_NOT_ENOUGH("isv.AMOUNT_NOT_ENOUGH", "账户余额不足");

    AlidayuSmsCode(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private final String code;
    private final String desc;

    /**
     * <p>从code获取AlidayuSmsCode，如果获取不了，返回null</p>
     *
     * @param code 查找的code
     * @return AlidayuSmsCode 可能为null
     */
    public AlidayuSmsCode getByCode(String code) {
        for (AlidayuSmsCode smsCode : AlidayuSmsCode.values()) {
            if (smsCode.code.equalsIgnoreCase(code)) {
                return smsCode;
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
